<?php

namespace App\Http\Controllers\Index;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{

    public function getTest()
    {
        $files = scandir(public_path('image/index'));

        $asset = asset('image/index',true);
        foreach (array_slice($files,2) as $k => $v) {
                $url[] = $asset .'/'. $v;
        }

        echo json_encode($url);

        //echo asset('image/index/feature1.jpg');
    }

    public function getGetinsurancetemplatedetail(Request $request)
    {
        $res = [
            [
                'id'=>1,
                'largeAvatar' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/19/top_banner.jpg',
                'product_name' => '团建保',
                'product_term'=>'保障期限:1 - 30天',
                'product_detail' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/19/angel_table.jpg',
                'product_rule' => [
                    'num' => '参保人数：3人以上，参保人员需达团体人员总数75%以上',
                    'age' => '参保年龄：18-65岁之间，无重大疾病无残障的健康人群',
                    'class' => '职业类别：1-3类',
                ],
                'pay_type'=>[['type'=>1,'cost'=>5]]

            ],
            [
                'id'=>2,
                'largeAvatar' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/7/top_banner.jpg',
                'product_name' => '极客保-意外险',
                'product_term'=>'保障期限: 一年',
                'product_detail' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/7/angel_table.jpg',
                'product_rule' => [
                    'num' => '最低参保人数：3人',
                    'age' => '参保年龄：18-65周岁',
                    'class' => '职业类别：1-3类 ',
                ],
                'pay_type'=>[['type'=>365,'cost'=>36],['type'=>30,'cost'=>4]]
            ],
            [
                'id'=>3,
                'largeAvatar' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/8/top_banner.jpg',
                'product_name' => '极客保-重疾型',
                'product_term' => '保障期限: 一年',
                'product_detail' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/8/angel_table.jpg',
                'product_rule' => [
                    'num' => '最低参保人数：3人',
                    'age' => '参保年龄：18-50周岁，平均年龄35岁以内',
                    'class' => '职业类别：1-3类 ',
                    'other' => '重大疾病保障有30天等待期'
                ],
                'pay_type' => [['type' => 365, 'cost' => 120], ['type' => 30, 'cost' => 11]]
            ],
            [
                'id'=>4,
                'largeAvatar' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/9/top_banner.jpg',
                'product_name' => '极客保-医疗型',
                'product_term' => '保障期限: 一年',
                'product_detail' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/9/angel_table.jpg',
                'product_rule' => [
                    'num' => '最低参保人数：3人',
                    'age' => '参保年龄：18-50周岁，平均年龄35岁以内',
                    'class' => '职业类别：1-3类',
                    'other'=>'适用人群：已参加社保人员，补充医疗需先经社保结算'
                ],
                'pay_type' => [['type' => 365, 'cost' => 360], ['type' => 30, 'cost' => 32]]
            ],
            [
                'id'=>5,
                'largeAvatar' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/10/top_banner.jpg',
                'product_name' => '极客保-重疾型',
                'product_term'=>'保障期限: 一年',
                'product_detail' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/10/angel_table.jpg',
                'product_rule' => [
                    'num' => '最低参保人数：3人',
                    'age' => '参保年龄：18-50周岁，平均年龄35岁以内',
                    'class' => '职业类别：1-3类',
                    'other' => '适用人群：已参加社保人员，补充医疗需先经社保结算',
                    'other1' => '重大疾病保障有30天等待期',
                ],
                'pay_type'=>[['type'=>365,'cost'=>699],['type'=>30,'cost'=>73]]
            ]
        ];
        echo json_encode($res[(int)$request['id'] - 1]);
    }

    public function getProduct()
    {
        $products = [
            [
                'id'=>1,
                'avatarUrl' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/19/product.jpg',
                'product_name' => '团建保',
                'product_feature'=>'产品特色: 30项健康检查，给优秀员工及其家属的健康关爱',
                'product_kind'=>'保障种类: 健康咨询+预约挂号、25项健康检查、检后复查',
                'product_term'=>'保障期限:1 - 30天',
                'pay_type'=>[['type'=>1,'cost'=>5]]
            ],
            [
                'id'=>2,
                'avatarUrl' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/7/product.jpg',
                'product_name' => '极客保-意外险',
                'product_feature'=>'产品特色: 扭伤、摔伤、地铁挤伤，重大事故全都保',
                'product_kind'=>'保障种类: 意外、意外医疗、猝死',
                'product_term'=>'保障期限: 一年',
                'pay_type'=>[['type'=>365,'cost'=>36],['type'=>30,'cost'=>4]]
            ],
            [
                'id'=>3,
                'avatarUrl' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/8/product.jpg',
                'product_name' => '极客保-重疾型',
                'product_feature' => '产品特色: 30种重大疾病，避免因病返贫，给员工一份切实关爱',
                'product_kind' => '保障种类: 重大疾病、猝死',
                'product_term' => '保障期限: 一年',
                'pay_type' => [['type' => 365, 'cost' => 120], ['type' => 30, 'cost' => 11]]
            ],
            [
                'id'=>4,
                'avatarUrl' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/9/product.jpg',
                'product_name' => '极客保-医疗型',
                'product_feature' => '产品特色: 1天1元钱，享20万意外+补充医疗',
                'product_kind' => '保障种类: 意外、意外医疗、猝死、补充医疗',
                'product_term' => '保障期限: 一年',
                'pay_type' => [['type' => 365, 'cost' => 360], ['type' => 30, 'cost' => 32]]
            ],
            [
                'id'=>5,
                'avatarUrl' => 'http://www.insgeek.com/public/insgeek-mobile2.0/img/insurancetemplate/10/product.jpg',
                'product_name' => '极客保-重疾型',
                'product_feature'=>'产品特色: 交通、意外、重疾、补充医疗全都保，实用性强，性价比高，适用广泛',
                'product_kind'=>'保障种类: 意外伤害、猝死、交通意外、重大疾病、补充医疗',
                'product_term'=>'保障期限: 一年',
                'pay_type'=>[['type'=>365,'cost'=>699],['type'=>30,'cost'=>73]]
            ]
        ];

        echo json_encode($products);
    }


    public function postIndex(Request $request)
    {
        //
        $dir = public_path('upload');
        //$request->file('photo');
        $files = $request->files->all();
//        print_r($files);
//        exit();
        $log = [];
        /*foreach ($files as $k=>$v) {
            if ($request->hasFile($k)) {
                if ($request->file($k)->isValid()) {
                    //$file = $request->file('photo');
                    $fileName = $request->file($k)->getClientOriginalName();
                    //$fileType = $request->file($k)->getClientOriginalExtension();
                    $request->file($k)->move($dir,$fileName);
                    $log[] = "上传成功";
                }
            }
        }*/
        if ($request->hasFile('photo')) {
            if ($request->file('photo')->isValid()) {
                //$file = $request->file('photo');
                //$fileName = $request->file('photo')->getClientOriginalName();
                $fileName = $request->input('fileName');
                //$fileType = $request->file($k)->getClientOriginalExtension();
                $request->file('photo')->move($dir,$fileName);
                $log[] = "上传成功";
            }
        }

        return \Response::json($log);


        /*if ($request->isMethod('post')) {
            return \Response::json($request->input());
        } else {
            return \Response::json('123');
        }*/
    }

    public function getUpload()
    {
        $files = scandir(public_path('upload'));

        $asset = asset('upload',true);
        foreach (array_slice($files,2) as $k => $v) {
            $url[] = $asset .'/'. $v;
        }

        echo json_encode($url);

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
